var app = getApp();
Page({
    data:{
        wxuser : null,
        order : null,
        options : null,
        value : -1,
        reason : [],
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
        self.setData({
            options : options,
        });
        app.com.auth(function(user){
            app.com.http('order','POST',{oid:options.id,op:'refundinfo'},0,false,'','',function(res){
                if (!res.data.errno) {
                    self.setData({
                        Pagetheme : res.data.data.params.style,
                        order : res.data.data.order,
                        good : res.data.data.good,
                        inited : true,
                        params : res.data.data.params,
                        reason : res.data.data.reason,
                    });
                    // 关闭下拉刷新
                    wx.stopPullDownRefresh();
                }else{
                    app.com.alert(res.data.message);
                }
            });
        });
        wx.setNavigationBarTitle({
          title:  '退款申请',
        });

    },
    dealorder( e ){
        var self = this;
        if( this.data.value*1 == -1 ){
            app.com.alert('请选择原因');
            return false;
        }
        if( self.data.reason[self.data.value] == '请选择原因' ){
            app.com.alert('请选择原因');
            return false;
        }

        var id = self.data.order.id;
        var postdata = {
            oid : id,
            op:'applyback',
            reason : self.data.reason[self.data.value] ? self.data.reason[self.data.value] : '',
        };

        var nostr = '确定申请退款吗？';
        app.com.confirm(nostr,function(){
            app.com.http('order','POST',postdata,0,true,'','',function(res){
                if ( !res.data.errno && res.data.errno !== undefined ) {
                    app.com.alert(res.data.message,function(){

                        wx.navigateBack();
                    });
                }else{
                    app.com.alert(res.data.message);
                }
            });
        });
    },
    bindChange(e){
        this.setData({
            value : e.detail.value[0]
        })
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },
    catchtouchmove : function(){
        return false;
    },
    callphone : function(e){
        app.com.callphone( e );
    },
    showkefuimg : function(e){
        app.com.alert('长按图片识别二维码联系客服',function(){
            wx.previewImage({
                current: e.currentTarget.dataset.img,
                urls: [e.currentTarget.dataset.img]
            });
        });
    },
    copy(e){
        wx.setClipboardData({
            data : e.currentTarget.dataset.copy
        })
    },
    FormIdsubmit : function(e){
        if( app.globalData.formarr.length <= 20 ) app.globalData.formarr.push(e.detail.formId);
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },
})